package FilesGenerator

import xml.{PrettyPrinter, XML}

/**
 * Created by IntelliJ IDEA.
 * User: SDi
 * Date: 12.04.11
 * Time: 14:01
 * To change this template use File | Settings | File Templates.
 */

object UserConfig {

  val filePath = "configs/UserConfig.sdpm"

  var scalaPath = ""
  var androidSdkPath = ""
  var proguardPath = ""

  // file exist and is valid
  def exists(): Boolean = {
    var retVal = false
    if(new java.io.File(filePath).exists()){
      get()
       if(!scalaPath.isEmpty & !androidSdkPath.isEmpty& !proguardPath.isEmpty)
         retVal = true
    }
    retVal
  }

  def get(): Unit = {

    val file = XML.loadFile(filePath)

    scalaPath = (file \\ "scalac" \ "@path") text;
    androidSdkPath = (file \\ "androidSdk" \ "@path") text;
    proguardPath = (file \\ "proguard" \ "@path") text;
  }


  def save(): Unit = {

    var config =
      <configs>
          <scalac path={scalaPath}/>
          <androidSdk path={androidSdkPath}/>
          <proguard path={proguardPath}/>
      </configs>

    XML.save(FileManager.createFile(filePath), XML.loadString(new PrettyPrinter(80, 3).format(config)), "UTF-8", true, null)
  }

}